package it.mauriziobasile.sincrodir.entita;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Filtro {

	private String pattern;
	private boolean tuttiTranne;
	private boolean solo;
	
	
	public Filtro(String patt) {
		this.pattern = patt;
		setTuttiTranne();
	}
	
	public Filtro(String patt,boolean solo){
		this(patt);
		if (solo)
			setSolo();
	}
	
	
	public boolean devePassare(File file){
		String fname = file.getName();
		Matcher matcher = Pattern.compile(pattern).matcher(fname);
		return solo==matcher.matches();
	}
	
	public String getPattern() {
		return pattern;
	}
	public void setPattern(String pattern) {
		this.pattern = pattern;
	}
	public boolean isTuttiTranne() {
		return tuttiTranne;
	}
	public void setTuttiTranne() {
		this.tuttiTranne = true;
		this.solo = false;
	}
	public boolean isSolo() {
		return solo;
	}
	public void setSolo() {
		this.solo = true;
		this.tuttiTranne=false;
	}

}
